package cn.project.lemontree.service.impl;

import cn.project.lemontree.bean.Child;
import cn.project.lemontree.service.ChildService;
import cn.project.lemontree.dao.ChildDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;

@Service("childService")
public class ChildServiceImpl extends ServiceImpl<ChildDao, Child> implements ChildService {
    @Resource
    private ChildDao childDao;

    @Override
    public List<Child> listpage(int page, int size, String childName, String className) {
        return childDao.listPage((page-1)*size,size,childName,className);
    }

    @Override
    public int count(String childName, String className ) {
        return childDao.count(childName,className);
    }

    @Override
    public boolean saveChild(Child child) {
        return childDao.save(child)>0;
    }

    @Override
    public boolean updateChild(Child child) {
        return childDao.update(child)>0;
    }

    @Override
    public List<Child> findChildrenByid(Integer classId){
        return childDao.findChildrenByid(classId);
    }

    @Override
    public boolean setClass(Integer invitationCode, Integer childId) {
        return childDao.setClass(invitationCode,childId)>0;
    }

    @Override
    public List<Child> findChild(Integer parentId){
        return childDao.findChild(parentId);
    }

    @Override
    public int countChild(Integer parentId){
        return childDao.countChild(parentId);
    }

    @Override
    public int countClass(List<Child> list){
        HashSet<Integer> set = new HashSet<>();
        for(Child child : list){
            set.add(childDao.countClass(child.getChildId()));
        }
        return set.size();
    }

    @Override
    public Child research(String childName,String birth){
        return childDao.research(childName,birth);
    }
}
